FROM python:3.11

ENV PYTHONUNBUFFERED=1

WORKDIR /backend
COPY ./backend/requirements.txt requirements.txt
RUN python3 -m pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt

COPY ./backend .
COPY ./backend/conf/docker.py conf/env.py

# 使用 Django 开发服务器启动项目,性能较差
#CMD ["python", "manage.py", "runserver", "0.0.0.0:9901"]
# 运行数据库迁移并启动 Gunicorn（推荐用法）
#CMD ["sh", "-c", "python manage.py makemigrations&&python manage.py migrate && gunicorn tushu.wsgi:application -b 0.0.0.0:9901"]

#CMD ["daphne", "-b", "0.0.0.0", "-p", "9901", "tushu.asgi:application"]
CMD ["sh", "-c", "python manage.py makemigrations system tushu && python manage.py makemigrations && python manage.py migrate && python manage.py init && python manage.py init_area && gunicorn tushu.wsgi:application -b 0.0.0.0:9901"]